aboutsummaryrefslogtreecommitdiff
path: root/src/routes/tools/[tool]/+page.svelte
blob: bd236d110afd0c64967c35ac790cc3403de25587 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script lang="ts">
	import ActivityHistory from '$lib/Tools/ActivityHistory/Tool.svelte';
	import Wrapped from '$lib/Tools/Wrapped.svelte';
	import EpisodeDiscussionCollector from '$lib/Tools/EpisodeDiscussionCollector.svelte';
	import CharacterBirthdays from '$lib/Tools/Birthdays.svelte';
	import SequelSpy from '$lib/Tools/SequelSpy.svelte';
	import { closest } from '$lib/Error/path';
	import HeadTitle from '$lib/HeadTitle.svelte';
	import RandomFollower from '$lib/Tools/RandomFollower.svelte';
	import DumpProfile from '$lib/Tools/DumpProfile.svelte';
	import { tools } from '$lib/Tools/tools.js';
	import { onMount } from 'svelte';
	import { goto } from '$app/navigation';
	import Picker from '$lib/Tools/Picker.svelte';

	export let data;

	let tool = data.tool ?? 'default';

	onMount(() => {
		if (tool === 'default') goto('/tools');
	});

	$: suggestion = closest(tool, Object.keys(tools));
</script>

<Picker bind:tool />

{#if !Object.keys(tools).includes(tool)}
	<HeadTitle route="Tools" path="/tools" />

	<div class="card">
		<p>Tool not found.</p>

		<blockquote style="margin: 0 0 0 1.5rem;">
			Did you mean "<a
				href={`/tools/${tools[suggestion].id}`}
				on:click={() => (tool = suggestion)}
				style={suggestion === '...' ? 'pointer-events: none; color: inherit;' : ''}
			>
				{suggestion === '...' ? '...' : tools[suggestion].name}</a
			>"?
		</blockquote>
	</div>
{:else}
	<HeadTitle route={tools[tool].name} path={`/tools?tool=${tool}`} />

	{#if tool === 'activity_history'}
		<ActivityHistory user={data.user} />
	{:else if tool === 'wrapped'}
		<Wrapped user={data.user} />
	{:else if tool === 'discussions'}
		<EpisodeDiscussionCollector />
	{:else if tool === 'birthdays'}
		<CharacterBirthdays />
	{:else if tool === 'sequel_spy'}
		<SequelSpy user={data.user} />
	{:else if tool === 'random_follower'}
		<RandomFollower />
	{:else if tool === 'dump_profile'}
		<DumpProfile />
	{/if}
{/if}